"""
通知相关的 Pydantic Schemas
用于 API 请求验证和响应序列化
"""
from pydantic import BaseModel, Field
from typing import Optional, Any
from datetime import datetime


class NotificationBase(BaseModel):
    """通知基础 Schema"""
    title: str = Field(..., description="通知标题", max_length=255)
    content: str = Field(..., description="通知内容")
    type: str = Field(default="system", description="通知类型：system/success/warning/error")
    status: int = Field(default=1, description="状态：0禁用 1启用")
    extra_data: Optional[dict] = Field(None, description="额外数据")


class NotificationCreate(NotificationBase):
    """创建通知请求 Schema"""
    user_id: int = Field(..., description="用户ID")


class NotificationUpdate(BaseModel):
    """更新通知请求 Schema"""
    title: Optional[str] = Field(None, description="通知标题")
    content: Optional[str] = Field(None, description="通知内容")
    type: Optional[str] = Field(None, description="通知类型")
    is_read: Optional[bool] = Field(None, description="是否已读")
    status: Optional[int] = Field(None, description="状态")


class NotificationResponse(BaseModel):
    """通知响应 Schema"""
    id: int
    user_id: int
    title: str
    content: str
    type: str
    is_read: bool
    status: int
    extra_data: Optional[dict]
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True  # Pydantic v2 使用 from_attributes
        # orm_mode = True  # Pydantic v1 使用 orm_mode


class NotificationListResponse(BaseModel):
    """通知列表响应 Schema"""
    total: int = Field(..., description="总数")
    page: int = Field(..., description="当前页码")
    page_size: int = Field(..., description="每页数量")
    items: list[NotificationResponse] = Field(..., description="通知列表")
    unread_count: int = Field(..., description="未读数量")


class NotificationQueryParams(BaseModel):
    """通知查询参数 Schema"""
    page: int = Field(1, ge=1, description="页码")
    page_size: int = Field(20, ge=1, le=100, description="每页数量")
    is_read: Optional[bool] = Field(None, description="是否已读筛选")
    type: Optional[str] = Field(None, description="通知类型筛选")


















